<?php

namespace App\Model\Shipping;

use App\Constants\ShippingTemplatesType;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;

/**
 * @property integer $id
 * @property string $name
 * @property boolean $type
 * @property boolean $appoint
 * @property boolean $no_delivery
 * @property integer $sort
 * @property integer $add_time
 * @property integer $create_time
 * @property integer $update_time
 * @property integer $delete_time
 */
class ShippingTemplates extends Model
{
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'shipping_templates';

    protected $fillable = [
        'name',
        'type',
        'appoint',
        'no_delivery',
        'sort',
        'add_time',
        'create_time',
        'update_time',
        'delete_time',
    ];

    protected $appends = [
        'type_format'
    ];

    public function getTypeFormatAttribute()
    {
        return $this->checkAttributes('type', function ($type) {
            return ShippingTemplatesType::getMessage($type);
        });
    }

    public function ShippingTemplatesRegion()
    {
        return $this->hasMany(ShippingTemplatesRegion::class, 'temp_id', 'id');
    }
}
